﻿@model S4Store.Models.AfterSaleReport.AfterSaleReportServiceAdvisorModel
@{
    ViewBag.Title = "FrontServiceIndex";
    Layout = null;
    var container = "div" + Guid.NewGuid().ToString();
}

@{
    
    if(Model.StandardConfig==null)
    {
        <text>目标未配置</text>
        return;
    }

    int 月应招徕回厂目标数 = Model.MonthTargets.Sum(o => o.BYYZHCMBS_ReturnFactoryTarget);
    int 实际招徕回厂目标数 = Model.SADayDatas.Sum(o => o.DHZLKHS_InviteByTelNum);
    int 应时招徕数 = (int)Math.Round( 月应招徕回厂目标数 * ViewBag.时间进度,0);
    decimal 招徕实施率目标 = Model.StandardConfig.招徕实施率目标;
    decimal 招徕实施率实际 = (月应招徕回厂目标数 == 0 ? 0 : ((decimal)实际招徕回厂目标数 / (decimal)月应招徕回厂目标数)) * 100;


    int 累计实现预约回厂数 = Model.SADayDatas.Sum(o => o.SXYYHCS);
    int 累计完成入厂台次 = Model.SADayDatas.Sum(o => o.SGRCTC_AccidentToFactory + o.WXRCTC_MaintentceToFactory);
    decimal 预约成功率实际 = (累计完成入厂台次 == 0 ? 0 : ((decimal)累计实现预约回厂数 / (decimal)累计完成入厂台次)) * 100;
    decimal 预约成功率目标 = Model.StandardConfig.预约成功率目标;
    int 月应时预约数目标 = (int)(Model.MonthTargets.Sum(o => o.BYWXRCTCMB_MaintenceCarToFactoryTarget + o.BYSGCRCTCMB_AccidentCarToFactoryTarget+o.BYYSSWKBYS_5KMaintenceTarget+o.BYYSSSQBYS_10KMaintenceTarget) * 预约成功率目标/100);
    int 应时预约数 = (int)Math.Round(月应时预约数目标 * ViewBag.时间进度, 0);
    int 实际预约数 = Model.SADayDatas.Sum(o => o.SXYYHCS);

    //int 
    int 六个月未来店客户数 = Model.MonthTargets.Sum(o => o.LGYWHCZS) + Model.SADayDatas.Sum(o => o.XZLGYWHCS - o.LSKHCXHCS);
    int 四个月未来店客户数 = Model.MonthTargets.Sum(o => o.SGYWHCZS) + Model.SADayDatas.Sum(o => o.XZSGYWHCS);
    int 客户总数 = Model.MonthTargets.Sum(o => o.SYMFGKHZS_LastMonthManageCustomerNum-o.LGYWHCZS) + Model.SADayDatas.Sum(o => o.BYAKZCKKHS_ACard2CCard);
    decimal 隐形流失率 = Model.GetAvgYXLSL(Model.BarModel.Month.Year, Model.BarModel.Month.Month);
    decimal 事实流失率 = Model.GetAvgSSKHLSL(Model.BarModel.Month.Year, Model.BarModel.Month.Month);
    
    
 }

 <div style="height:100%; overflow:auto">
@Html.Action("ReportBar", "Common", Model.BarModel)


<div style="position:relative; width:100%">
    @{

        S4Store.Models.Chart.Column ChartModel = new S4Store.Models.Chart.Column();
        ChartModel.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
        //ChartModel.Name = "登记客户";
        ChartModel.YAxis = "前台服务管理关键KPI";
        //ChartModel.Width = 500;
        //ChartModel.Height = 300;
        ChartModel.XAxis.Add("招徕实施率");
        ChartModel.XAxis.Add("预约成功率");
        ChartModel.XAxis.Add("隐形流失率");
        ChartModel.XAxis.Add("事实流失率");
        //ChartModel.XAxis.Add("维修产值完成进度差");

        S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
        series1.Name = "目标";
        series1.Data.Add(Model.StandardConfig.招徕实施率目标);
        series1.Data.Add(Model.StandardConfig.预约成功率目标);
        series1.Data.Add(Model.StandardConfig.隐形流失率目标);
        series1.Data.Add(Model.StandardConfig.事实流失率目标);
        //series1.Data.Add(ViewBag.时间进度*100);
        ChartModel.Serieses.Add(series1);


        S4Store.Models.Chart.ChartSeries series2 = new S4Store.Models.Chart.ChartSeries();
        series2.Name = "实际";
        series2.Data.Add(招徕实施率实际);
        series2.Data.Add(预约成功率实际);
        series2.Data.Add(隐形流失率);
        series2.Data.Add(事实流失率);
            
        //series2.Data.Add((Model.应时产值 == 0 ? 0 : Model.实际产值 / Model.应时产值)*100);
        ChartModel.Serieses.Add(series2);
    
    
        @Html.Partial("../Chart/Column", ChartModel)
        <div style=" margin-left:70px; overflow:hidden">
        <table style="width:100%">
            <tr>
                <td align="center" width="30">
                @if (招徕实施率实际 < 招徕实施率目标)
                {
                    <a class="specialRed" href="@Url.Action("FrontService_ZLSSL", new { Month = Model.BarModel.Month.ToString("yyyy-MM-dd") })" target="navtab" title="招徕实施率">
                        <div class="value">@Math.Round((招徕实施率实际 - 招徕实施率目标),0,MidpointRounding.AwayFromZero)%</div>
                        <div class="rt">实际招徕数：@实际招徕回厂目标数</div>
                        <div class="rb">应时招徕数：@应时招徕数</div>
                    </a>
                }
                else
                {
                    <a class="specialGreen" href="@Url.Action("FrontService_ZLSSL", new { Month = Model.BarModel.Month.ToString("yyyy-MM-dd") })" target="navtab" title="招徕实施率">
                        <div class="value">@Math.Round((招徕实施率实际 - 招徕实施率目标),0,MidpointRounding.AwayFromZero)%</div>
                        <div class="rt">实际招徕数：@实际招徕回厂目标数</div>
                        <div class="rb">应时招徕数：@应时招徕数</div>
                    </a>
                }

                </td>

                <td align="center" width="30">
                @if (预约成功率实际 < 预约成功率目标)
                {
                    <a class="specialRed" href="@Url.Action("FrontService_YYCGL", new { Month = Model.BarModel.Month.ToString("yyyy-MM-dd") })" target="navtab" title="预约成功率">
                        <div class="value">@((预约成功率实际 - 预约成功率目标).toInt())%</div>
                        <div class="rt">实际预约数：@实际预约数</div>
                        <div class="rb">应时预约数：@应时预约数</div>
                    </a>
                }
                else
                {
                    <a class="specialGreen" href="@Url.Action("FrontService_YYCGL", new { Month = Model.BarModel.Month.ToString("yyyy-MM-dd") })" target="navtab" title="预约成功率">
                        <div class="value">@((预约成功率实际 - 预约成功率目标).toInt())%</div>
                        <div class="rt">实际预约数：@实际预约数</div>
                        <div class="rb">应时预约数：@应时预约数</div>
                    </a>
                }

                </td>

                <td align="center" width="30">
                @if (隐形流失率 > Model.StandardConfig.隐形流失率目标)
                {
                    <a class="specialRed" href="@Url.Action("FrontService_YXLSL", new { Month = Model.BarModel.Month.ToString("yyyy-MM-dd") })" target="navtab" title="隐形流失率">
                        <div class="value">@((隐形流失率 - Model.StandardConfig.隐形流失率目标).toInt())%</div>
                        <div class="rt">四个月未来店客户数：@四个月未来店客户数</div>
                    </a>
                }
                else
                {
                    <a class="specialGreen" href="@Url.Action("FrontService_YXLSL", new { Month = Model.BarModel.Month.ToString("yyyy-MM-dd") })" target="navtab" title="隐形流失率">
                        <div class="value">@((隐形流失率 - Model.StandardConfig.隐形流失率目标).toInt())%</div>
                        <div class="rt">四个月未来店客户数：@四个月未来店客户数</div>
                    </a>
                }

                </td>

                 <td align="center" width="30">
                @if (事实流失率 > Model.StandardConfig.事实流失率目标)
                {
                    <a class="specialRed" href="@Url.Action("FrontService_SSLSL", new { Month = Model.BarModel.Month.ToString("yyyy-MM-dd") })" target="navtab" title="事实流失率">
                        <div class="value">@((事实流失率 - Model.StandardConfig.事实流失率目标).toInt())%</div>
                        <div class="rt">六个月未来店客户数：@六个月未来店客户数</div>
                    </a>
                }
                else
                {
                    <a class="specialGreen" href="@Url.Action("FrontService_SSLSL", new { Month = Model.BarModel.Month.ToString("yyyy-MM-dd") })" target="navtab" title="事实流失率">
                        <div class="value">@((事实流失率 - Model.StandardConfig.事实流失率目标).toInt())%</div>
                        <div class="rt">六个月未来店客户数：@六个月未来店客户数</div>
                    </a>
                }

                </td>

            </tr>
        </table>
        </div>
        
    }
    
</div>
</div>

